package org.yuanqiframework.yuanqi.web.auth.utils;


import org.yuanqiframework.yuanqi.web.auth.annotation.Auth;

import java.util.Set;
import java.util.stream.Collectors;

public class AuthUtils {

    public static boolean hasRole(Auth auth, Set<String> roleSet) {
        //需角色访问
        String[] roles = auth.roles();

        if (roles.length > 0) {
            if (roleSet == null || roleSet.size() == 0) {
                return false;
            }
            roleSet = roleSet.stream().map(String::toLowerCase).collect(Collectors.toSet());
            for (String role : roles) {
                if (roleSet.contains(role.toLowerCase())) {
                    return true;
                }
            }
        }
        return false;
    }
}
